import 'package:flutter/material.dart';

/// TabView
/// 1. 创建TabController
/// 2. 创建Tab
/// 3. 为每一个Tab创建内容

class TabApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Tab Demo',
      theme: ThemeData(primarySwatch: Colors.red),
      home: TabAppPage(),
    );
  }
}

class TabAppPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() => TabAppPageState();
}

class TabAppPageState extends State<TabAppPage> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            title: Text('Tab Demo'),
            bottom: TabBar(tabs: [
              Tab(icon: Icon(Icons.directions_car)),
              Tab(icon: Icon(Icons.directions_transit)),
              Tab(icon: Icon(Icons.directions_bike))
            ]),
          ),
          body: TabBarView(children: [
            Tab(icon: Icon(Icons.directions_car)),
            Tab(icon: Icon(Icons.directions_transit)),
            Tab(icon: Icon(Icons.directions_bike))
          ]),
        ));
  }
}

class TabAppPageState1 extends State<TabAppPage> {
  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            title: Text('Tab Demo'),
            bottom: TabBar(tabs: [
              Tab(icon: Icon(Icons.directions_car)),
              Tab(icon: Icon(Icons.directions_transit)),
              Tab(icon: Icon(Icons.directions_bike))
            ]),
          ),
          body: TabBarView(children: [
            Tab(icon: Icon(Icons.directions_car)),
            Tab(icon: Icon(Icons.directions_transit)),
            Tab(icon: Icon(Icons.directions_bike))
          ]),
        ));
  }
}
